package org.tio.sitexxx.service.service.gl;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.sitexxx.service.cache.CacheConfig;
import org.tio.sitexxx.service.cache.Caches;
import org.tio.sitexxx.service.model.main.Retail;
import org.tio.sitexxx.service.vo.Const;
import org.tio.utils.cache.CacheUtils;
import org.tio.utils.cache.FirsthandCreater;
import org.tio.utils.cache.ICache;

public class RetailManageService {
    private static Logger log	= LoggerFactory.getLogger(RetailManageService.class);
    public static final RetailManageService	me	= new RetailManageService();

    public Page<Retail> RetailList(int pageNumber,int pageSize){
        String db = Const.Db.TIO_SITE_MAIN;
        String sqlid = "gl_retail.retailList";
        ICache cache  = Caches.getCache(CacheConfig.TETAIL_LIST);
        String key = pageNumber + "_" + pageSize;
        boolean putTempToCacheIfNull  = false;
        Page<Retail> page = CacheUtils.get(cache, key, putTempToCacheIfNull, new FirsthandCreater<Page<Retail>>() {
            @Override
            public Page<Retail> create() {
                SqlPara sqlPara = Db.use(db).getSqlPara(sqlid);
                Page<Retail> page = Retail.dao.paginate(pageNumber, pageSize,sqlPara);
                return page;
            }
        });
        return page;
    }
}
